﻿@{
    ViewBag.Title = "评价管理";
    ViewBag.PathToBtn = "/OrderComment/List";
    ViewBag.TextBtn = "刷新";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                评价列表
            </div>
            <div class="panel-body">
                <div class="dataTable_wrapper">
                    <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
                        <thead>
                            <tr>
                                <th>订单号</th>
                                <th>消费者</th>
                                <th>绑定店铺</th>
                                <th>评价内容</th>
                                <th>评价等级</th>
                                <th>评价时间</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">问题处理</h4>
            </div>
            <div class="modal-body">
                <form id="form0">
                    <table class="detail-tb" style=" margin: 0 auto; border-spacing: 10px">
                        <tr>
                            <td colspan="2">
                                <div class="input-group">
                                    <input type="hidden" id="HidId" />
                                    <span class="input-group-addon">店铺问题：</span>
                                    是:  
                                    <input type="radio" name="IsShopMistake" id="IsShopMistake" value="true" />
                                    否:   <input type="radio" name="IsShopMistake" id="IsShopMistake" checked="checked" value="false" />
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <div class="input-group">
                                    <input type="hidden" id="HidId1" />
                                    <span class="input-group-addon">处理结果：</span>
                                    <textarea id="DealResult" name="DealResult" maxlength="500" rows="5" cols="40"></textarea>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" style=" border:0 none">
                                <div class="input-group">
                                    <input type="hidden" id="hidId" />
                                    <input type="hidden" id="hidConsumerId" />
                                </div>
                            </td>
                        </tr>
                    </table>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="btnSave">确认</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="ChangeShopModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="max-width: 500px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">更改用户绑定店铺（<font color="red">仅显示已激活的店铺</font>）</h4>
            </div>
            <div class="modal-body">
                <div style="margin-bottom: 5px;">
                    <input type="text" class="form-control" placeholder="店铺名称" style="width: 409px;display: inline-block" id="shopKeyWords" />
                    <a class="btn btn-primary" onclick="searchShops();">查询</a>
                </div>
                <div class="table-responsive table-bordered" style="max-height: 250px;">
                    <table class="table">
                        <thead>
                            <tr>
                                <th>店铺名称</th>
                                <th style="text-align: center">操作</th>
                            </tr>
                        </thead>
                        <tbody id="shopsData"></tbody>
                    </table>
                    <input type="hidden" id="hidConsumerId" />
                </div>
            </div>
        </div>
    </div>
</div>
@section javascript{
    <script src="/Content/admin/dist/js/pagingHelper.js"> </script>
    <script type="text/javascript">
        var dataParams = {};
        var serverProcessPath = "/OrderComment/Listing";
        var showColumns = [
            { data: "OrderNo" },
            { data: "NickName" },
            { data: "shopName" },
            { data: "ReplyContent" },
            { data: "PointsStr" },
            { data: "AddTimeStr" },
            { data: "Action" }
        ];
        pagingHelper.Paging(serverProcessPath, dataParams, showColumns);
        function OrderCommentCheck(id) {
            document.location.href = '/Coupon/Details/' + id;
        }

        $(function () {
            $("#form0").validate({
                rules: {
                    DealResult: { required: true },
                },
                messages: {
                    DealResult: { required: "请填写处理结果" }
                }
            });
        })
        $('#myModal').on('hide.bs.modal', function () {
        
            $("#DealResult").val("");
            $('input:radio:Last').attr('checked', 'checked');
            $("#hidId").val("");
        })
        $("#btnSave").click(function () {
            var IsShopMistake = $("input[type='radio']:checked").val();
            if ($("#form0").valid()) {
                $.ajax({
                    type: 'post',
                    async: false,
                    url: '/OrderComment/Update',
                    data: { id: $("#hidId").val(), IsShopMistake: IsShopMistake, DealResult: $("#DealResult").val() },
                    success: function (result) {
                        if (result) {
                            $('#myModal').modal('hide');
                            alertify.success("处理成功");
                            $("#DealResult").val("");
                            $('input:radio:Last').attr('checked', 'checked');
                            $("#hidId").val("");
                            if (IsShopMistake == 'true') {
                                alertify.okBtn("更换").cancelBtn("取消").confirm("是否更换店铺？", function () {
                                    $('#ChangeShopModal').modal('show');
                                }, function () {
                                    setTimeout(function () { location.reload(); }, 1000);
                                })
                            }
                            else {
                                setTimeout(function () { location.reload(); }, 1000);
                            }
                        } else {
                            alertify.error("处理失败");
                        }

                    }
                });
            }
        });
        function HandleProblems(id, ConsumerId) {
            $("#hidConsumerId").val(ConsumerId);
            $("#hidId").val(id);
        }
        function HandleResult(id)
        {
            location.href = "/OrderComment/SeeDetails?id=" + id;
        }
        function confirmChangeShop(shopId) {
            alertify.okBtn("确定").cancelBtn("取消").confirm("确定将此用户绑定到此店铺吗？", function () {
                $.post("@Url.Action("ChangeShop", "Consumer")", "consumerId=" + $("#hidConsumerId").val() + "&shopId=" + shopId, function (data) {
                    if (data.Status) {
                        $("#ChangeShopModal").modal("hide");
                        reloadList();
                        alertify.success("绑定成功");
                    } else {
                        alertify.alert(data.Message);
                    }
                });
            }, function () {
                setTimeout(function () { location.reload(); }, 1000);
            });
        }

        function searchShops() {
            isSearched = true;
            $("#shopsData").html("");
            $.post("@Url.Action("GetActiveShopList", "Shops")", "keyWords=" + encodeURIComponent($("#shopKeyWords").val()), function (data) {
                if (data != null) {
                    for (var i = 0; i < data.length; i++) {
                        $("#shopsData").append("<tr><td>" + data[i].Name + "</td><td align='center'><a class='btn btn-info' onclick='confirmChangeShop(" + data[i].Id + ");'>绑定</a></td></tr>");
                    }
                }
            });
        }

        function reloadList() {
            pagingHelper.reloadWithDiffPath("@Url.Action("Listing")");
        }

    </script>
}